package cn.hp.customer.controller;

import cn.hp.customer.pojo.Customer;
import cn.hp.customer.pojo.Customer1;
import cn.hp.customer.service.CustomerService;
import cn.hp.customer.util.ResponseData;
import cn.hp.customer.util.SysLog;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/customerAdmin")
public class CustomerAdminController {

    @Autowired
    private CustomerService customerService ;

    // 设置跳转到客户管理首页
    @RequestMapping("/main")
    public String main(){
        // 跳转主页之前 模拟进行了管理员登录
        return "/WEB-INF/back/customer/main.html";
    }

    // 设置跳转客户个人信息页面
    @RequestMapping("/customerInfo")
    public String customerInfo(){
        return "/WEB-INF/back/customer/customerInfo.html";
    }

    @RequestMapping("/customerUpdate")
    public String customerUpdate(){
        return "/WEB-INF/back/customer/customerUpdate.html";
    }

    @RequestMapping("/customerShow")
    @SysLog(operation = "跳转修改用户展示页" , method = "customerShow_page" , module = "后端管理")
    public String customerShow(){
        return "/WEB-INF/back/customer/customerShow.html";
    }

    @ResponseBody
    @RequestMapping("/update")
    // 无法将参数注入到对象中?
//    public String update(int id , String passengerName , String education , String birthday , String gender, String phone ){
    public String update( Customer1 customer ){
        System.out.println(customer);
        ResponseData responseData = customerService.update(customer);
        return JSON.toJSONString(responseData);
    }

    @ResponseBody
    @RequestMapping("/updateShow")
    @SysLog(operation = "查询修改用户" , method = "update_showCustomer" , module = "后端管理")
    public String updateShow(@RequestParam int id){
        ResponseData responseData = customerService.updateShow(id);
        return JSON.toJSONString(responseData) ;
    }

    @ResponseBody
    @RequestMapping("/showCustomer")
    @SysLog(operation = "查询全部用户" , method = "showCustomer" , module = "后端管理")
    public String showCustomer(int page , int limit , @RequestParam( required = true , defaultValue = "") String phoneNumber ){
        // 创建一个分页对象 ( 当前页数、总页数、总记录数、每页条数、每页数据 )
        ResponseData responseData = customerService.findAllByPage(page , limit ,phoneNumber);
        System.out.println(responseData);
        return JSON.toJSONString(responseData);

        // 展示全部的客户信息  未分页
//        ResponseData responseData = customerService.findAll();
//        System.out.println("-----------");
//        System.out.println(responseData.getData());
//        return JSON.toJSONString(responseData);
    }

    @ResponseBody
    @RequestMapping("/deleteCustomer")
    @SysLog(operation = "删除用户" , method = "deleteCustomer" , module = "后端管理")
    public String deleteCustomer(int id){
        ResponseData responseData = customerService.deleteCustomer(id);
        return JSON.toJSONString(responseData);
    }


    // aop 面向切面编程，往日志中添加 日志记录表(operator、time、specificOperation、方法名、执行时间、结果、)
    // 1.配置通知类  2.配置切面( 配置切入点、配置通知类型 )

}
